package com.hermes.test;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.hermes.biz.common.model.comment.UserCommentDisplayUnitDO;
import com.hermes.biz.common.model.item.ItemUserRelationDO;
import com.hermes.biz.common.util.string.StringUtil;
import com.hermes.biz.manager.user.UserOperateManager;
import com.hermes.biz.manager.usermodelextra.UserModelExtraManager;
import com.hermes.biz.service.item.UserItemRelationService;
import com.hermes.biz.service.user.UserConcernInfoService;
import com.hermes.common.action.AsynBaseAction;
import com.hermes.common.util.ParameterParserUtil;

public class Phome extends AsynBaseAction {

    private static final long             serialVersionUID = 4576336969070199220L;

    private static Logger                 log              = Logger.getLogger(Phome.class);

    private UserItemRelationService       urs;

    private UserConcernInfoService        userConcernInfoService;

    public int                            itemLVcount      = 0;

    public UserOperateManager             userOperateManager;

    private UserModelExtraManager         userModelExtraManager;

    public long                           fansCount        = 0;

    public long                           eyeonCount       = 0;

    public boolean                        isLogin          = true;

    public String                         username         = "";

    public String                         userId           = null;

    public String                         logoyet          = "0";

    public boolean                        showInfo         = false;

    public List<UserCommentDisplayUnitDO> newMessageList;

    public List<ItemUserRelationDO>       userCollectItems;

    @Override
    public String execute() throws Exception {

        userId = ParameterParserUtil.getParameter("userid");
        String showmessage = ParameterParserUtil.getParameter("sm");
        if (StringUtil.isNotBlank(showmessage)) {
            showInfo = true;
        }

        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();
        try {
            username = (String) session.getAttribute("userName");
        } catch (Exception e) {
        }
        if (username == null || username == "") {
            setLogin(false);
        }
        log.error("Phome-user-id" + userId);
        if (isLogin && userId != null && StringUtil.isNumOnly(userId)) {
            long userIdNum = Long.parseLong(userId);
            eyeonCount = getEyeonCount(userIdNum);
            fansCount = getFansCount(userIdNum);
            newMessageList = userConcernInfoService.getUserConcernInfoList(userIdNum);
            log.error("Phome-user-eyeoncount" + eyeonCount);
            log.error("Phome-user-fansCount" + fansCount);
            log.error("Phome-user-newMessageList-size" + newMessageList.size());

            List<ItemUserRelationDO> userLikeItems = urs.getUserInterestedItems(Long
                .parseLong(userId));
            userCollectItems = userLikeItems;
        }

        return SUCCESS;
    }

    public long getEyeonCount(long userID) {
        eyeonCount = userModelExtraManager.getEyeonCount(userID);
        return eyeonCount;
    }

    public long getFansCount(long userID) {
        fansCount = userModelExtraManager.getFansCount(userID);
        return fansCount;
    }

    public UserItemRelationService getUrs() {
        return urs;
    }

    public void setUrs(UserItemRelationService urs) {
        this.urs = urs;
    }

    public UserModelExtraManager getUserModelExtraManager() {
        return userModelExtraManager;
    }

    public void setUserModelExtraManager(UserModelExtraManager userModelExtraManager) {
        this.userModelExtraManager = userModelExtraManager;
    }

    public void setUserOperateManager(UserOperateManager userOperateManager) {
        this.userOperateManager = userOperateManager;
    }

    public boolean isLogin() {
        return isLogin;
    }

    public void setLogin(boolean isLogin) {
        this.isLogin = isLogin;
    }

    public UserConcernInfoService getUserConcernInfoService() {
        return userConcernInfoService;
    }

    public void setUserConcernInfoService(UserConcernInfoService userConcernInfoService) {
        this.userConcernInfoService = userConcernInfoService;
    }

    public List<UserCommentDisplayUnitDO> getNewMessageList() {
        return newMessageList;
    }

    public void setNewMessageList(List<UserCommentDisplayUnitDO> newMessageList) {
        this.newMessageList = newMessageList;
    }

    public boolean isShowInfo() {
        return showInfo;
    }

    public void setShowInfo(boolean showInfo) {
        this.showInfo = showInfo;
    }

    public List<ItemUserRelationDO> getUserCollectItems() {
        return userCollectItems;
    }

    public void setUserCollectItems(List<ItemUserRelationDO> userCollectItems) {
        this.userCollectItems = userCollectItems;
    }

}
